Repository navigation
Conversation
Follow-up to RedHatInsights#2351, which only switched RBAC to the v2 uri. - resolve RBAC only from v2 (drop v1 and unused RbacURL/RBAC_URL) - add the SSO bearer when the endpoint is authenticated, trust ca_certificate, fail closed on missing credentials, non-https or token errors - redact Authorization in trace request dumps - local cdappconfig gets a v2 rbac endpoint
Reviewer's GuideData structuresAdd RBAC authentication and CA certificate fields to the shared core configuration used by the RBAC client.
ImplementationBuild RBAC requests from the v2 endpoint metadata, add a bearer token and trusted CA for authenticated endpoints, fail closed on authentication errors, and remove the cached RBAC URL.
Redact Authorization headers from HTTP request dumps so bearer tokens are not exposed in trace logs.
ConfigurationConfigure the local Clowder v2 RBAC endpoint and remove the obsolete test environment setting.
TestsCover v2 RBAC configuration resolution, authenticated bearer and CA handling, and fail-closed behavior for missing credentials, non-HTTPS endpoints, and token errors.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="manager/middlewares/rbac.go" line_range="80" />
<code_context>
+ if err := requireAuthConfig(); err != nil {
+ return "", err
+ }
+ token, err := credentials.GetToken(ctx, auth.GetTokenOptions{HttpClient: &http.Client{Timeout: tokenTimeout}})
+ if err != nil {
+ return "", errors.Wrap(err, "fetching RBAC bearer token")
</code_context>
<issue_to_address>
**HTTP SSO exposes credentials**
When the configured issuer or discovered token endpoint uses HTTP outside a trusted loopback test environment, `bearerHeader` passes the issuer to `credentials.GetToken` without requiring HTTPS for the issuer or discovered token endpoint, so OAuth client credentials travel in plaintext and are exposed to network observers.
Require HTTPS for the configured issuer and discovered token endpoint before sending OAuth credentials.
</issue_to_address>
### Comment 2
<location path="manager/middlewares/rbac.go" line_range="106" />
<code_context>
+ if err != nil {
+ return nil, err
+ }
+ headers["Authorization"] = bearer
+ }
+
</code_context>
<issue_to_address>
**Bearer token follows redirects**
When the RBAC endpoint responds with a redirect to an attacker-controlled subdomain of its host, `http.Client` follows redirects by default, and Go forwards sensitive headers to subdomains of the original host; a redirect from the RBAC endpoint to an attacker-controlled subdomain therefore receives the service bearer token.
Disable redirects for authenticated RBAC requests or reject redirects before forwarding the Authorization header.
</issue_to_address>
### Comment 3
<location path="manager/middlewares/rbac.go" line_range="114-116" />
<code_context>
- DefaultHeaders: map[string]string{xRHIdentity: identity},
+ DefaultHeaders: headers,
}
if rbacURL == "" {
rbacURL = utils.FailIfEmpty(utils.CoreCfg.RbacAddress, "RBAC_ADDRESS") + base.RBACApiPrefix +
"/access/?application=patch,inventory,content-sources"
}
- return &client
</code_context>
<issue_to_address>
**Concurrent RBAC checks fail**
When the first RBAC checks arrive concurrently, `makeClient` writes `rbacURL` without synchronization while `isAccessGranted` reads it for `Request`, causing a data race that can produce malformed RBAC request URLs and failed permission lookups.
Synchronize `rbacURL` initialization and reads.
Also at `manager/middlewares/rbac.go:102-105`.
</issue_to_address>
### Comment 4
<location path="manager/middlewares/rbac_auth_test.go" line_range="99-100" />
<code_context>
+ resetRbacClient(t)
+
+ // token endpoint failing
+ failing := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ http.Error(w, "nope", http.StatusInternalServerError)
+ }))
+ defer failing.Close()
</code_context>
<issue_to_address>
**Token failure is not exercised**
When the issuer discovery request is made against the failing server, `TestRbacAuthenticatedFailsClosed` gets an error before a token request: the handler returns 500 for the issuer discovery request as well as `/token`. Its error and nil-client assertions therefore pass even if token-endpoint errors are mishandled.
Return valid issuer metadata for discovery and return 500 only from the token endpoint.
</issue_to_address>
### Comment 5
<location path="manager/middlewares/rbac_auth_test.go" line_range="111-113" />
<code_context>
+
+ // missing credentials
+ setAuthConfig("https://ewgw:443", failing.URL)
+ utils.CoreCfg.KesselAuthClientSecret = ""
+ client, err = makeClient(base.Context, "xrhid")
+ assert.Error(t, err)
+ assert.Nil(t, client)
+
</code_context>
<issue_to_address>
**Missing credentials check is masked**
When the configured client secret is empty while the SSO endpoint continues returning errors, `TestRbacAuthenticatedFailsClosed` still gets an error from the failing SSO server if `requireAuthConfig` stops rejecting the cleared client secret: `credentials` was created with valid credentials, and the token request still fails. The assertions therefore pass without verifying that missing credentials cause the failure.
Use a successful fake SSO endpoint for this subcase and verify that `makeClient` rejects the missing secret without requesting a token.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 5 findings to address first, and if the authenticated-endpoint configuration or token handling is wrong, RBAC permission checks may be made without the intended service identity or may fail closed. An overly permissive response could allow protected operations to run; reverting restores the previous calls but cannot undo actions taken while the change was live.
Blocking findings: manager/middlewares/rbac.go:80, manager/middlewares/rbac.go:106, manager/middlewares/rbac.go:116, manager/middlewares/rbac_auth_test.go:100, manager/middlewares/rbac_auth_test.go:113
Compute the RBAC URL per call instead of caching it in an unsynchronized global. Make the fail-closed tests reach the token endpoint and assert that missing credentials never request a token.
Follow-up to #2351, which only switched RBAC to the v2 uri.
Secure Coding Practices Checklist GitHub Link
Secure Coding Checklist
Summary by Sourcery
Secure RBAC integration by using Clowder v2 endpoint metadata and enforcing authenticated HTTPS requests when configured.
New Features:
Bug Fixes:
Enhancements:
Deployment:
Tests: